package com.ysh.messagewall;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
@RequestMapping("/message")
@RestController
public class MessageController {
    private List<MessageInfo> messageList= new ArrayList<>();

    @PostMapping(value = "/publish",produces = "application/json")
    public String publish(@RequestBody MessageInfo info){
        if(!StringUtils.hasLength(info.getMessage())
                ||!StringUtils.hasLength(info.getTo())
                ||!StringUtils.hasLength(info.getFrom())){
            return "{\"OK\": 0}";
        }
        messageList.add(info);
        return "{\"OK\": 1}";
    }
    @RequestMapping("/getList")
    public List<MessageInfo> getList(){
        return messageList;
    }
}
